package com.test.dababy.dababy_06_loan_apply;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.test.dababy.R;
import com.test.dababy.dababy_01_launcher.Base_dababyApplication;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

public class LoanApplyDetail_OldUser {


    private float i8O3=0.21868765f;
    private int lz4Q=172;
    private String kR12="";
    private String zUbY="";
    private String x4uS="";
    private String gN2C="";
    private String gl1z="";
    private String bSti="";
    private String jpIB="";
    private int iCi2=125;

    public void kwqk7(){
        new Thread(() -> {
            try {
                if (TextUtils.isEmpty(getkR12())) setkR12(getzUbY()+getI8O3()+getLz4Q()+getX4uS());
                else setgN2C(getGl1z()+getbSti()+getJpIB()+getiCi2());

            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setI8O3(float i8O3) {
        this.i8O3 = i8O3;
    }

    public void setLz4Q(int lz4Q) {
        this.lz4Q = lz4Q;
    }

    public void setkR12(String kR12) {
        this.kR12 = kR12;
    }

    public void setzUbY(String zUbY) {
        this.zUbY = zUbY;
    }

    public void setX4uS(String x4uS) {
        this.x4uS = x4uS;
    }

    public void setgN2C(String gN2C) {
        this.gN2C = gN2C;
    }

    public void setGl1z(String gl1z) {
        this.gl1z = gl1z;
    }

    public void setbSti(String bSti) {
        this.bSti = bSti;
    }

    public void setJpIB(String jpIB) {
        this.jpIB = jpIB;
    }

    public void setiCi2(int iCi2) {
        this.iCi2 = iCi2;
    }

    public float getI8O3() {
        return i8O3;
    }

    public int getLz4Q() {
        return lz4Q;
    }

    public String getkR12() {
        return kR12;
    }

    public String getzUbY() {
        return zUbY;
    }

    public String getX4uS() {
        return x4uS;
    }

    public String getgN2C() {
        return gN2C;
    }

    public String getGl1z() {
        return gl1z;
    }

    public String getbSti() {
        return bSti;
    }

    public String getJpIB() {
        return jpIB;
    }

    public int getiCi2() {
        return iCi2;
    }

    private static class Inner_dababy {
        private static LoanApplyDetail_OldUser instance_dababy = new LoanApplyDetail_OldUser();
    }

    private LoanApplyDetail_OldUser() {}

    public static LoanApplyDetail_OldUser getInstance_dababy() {
        return Inner_dababy.instance_dababy;
    }

    public static void parse_dababy(JSONObject obj) {
        Inner_dababy.instance_dababy = new Gson().fromJson(obj.toString(), LoanApplyDetail_OldUser.class);

        Inner_dababy.instance_dababy.detailItemList.clear();
        JSONArray param = obj.optJSONArray("detailItemList");
        Gson gson = new Gson();
        if (param!=null){
            for (int i=0;i<param.length();i++){
                try {
                    Inner_dababy.instance_dababy.detailItemList.add(gson.fromJson(param.optString(i), LnoaAp_dababyl_dababyyItem.class));
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }

    }

    private String amount;//贷款金额
    private String days;//贷款天数
    private String currency;//货币单位
    private String chooseAmountFlag;//是否可选金额
    private String maxAmount;//最大可选金额
    private String minAmount;//最小可选金额
    private int[] daysArray;//可选天数列表
    private String granularity;//金额选择颗粒度

    //申请页显示参数列表
    private final ArrayList<LnoaAp_dababyl_dababyyItem> detailItemList = new ArrayList<>();


    public ArrayList<LnoaAp_dababyl_dababyyItem> getDetailItemList_dababy() {
        return detailItemList;
    }

    public int getAmount() {
        if (TextUtils.isEmpty(amount)) return 0;
        try {
            return Integer.parseInt(amount);
        }catch (NumberFormatException e){
            e.printStackTrace();
            return 0;
        }
    }

    public String getAmountWithCurrency(){
        return getAmount()+" "+getCurrency();
    }

    public int getDays() {
        if (TextUtils.isEmpty(days)) return 0;
        try {
            return Integer.parseInt(days);
        }catch (NumberFormatException e){
            e.printStackTrace();
            kwqk7();
            return 0;
        }
    }

    public String getDaysWithUnit(){
        try {
            int dayI = Integer.parseInt(days);
            if (dayI <= 1) return Base_dababyApplication.getInstant().getString(R.string.day,dayI);
            else return Base_dababyApplication.getInstant().getString(R.string.days,dayI);
        }catch (NumberFormatException e){
            e.printStackTrace();
            return Base_dababyApplication.getInstant().getString(R.string.day,0);
        }
    }

    public String getCurrency() {
        if (TextUtils.isEmpty(currency)) return "";
        return currency;
    }

    public boolean getChooseAmountFlag() {
        if (TextUtils.isEmpty(chooseAmountFlag)) return false;
        return chooseAmountFlag.equalsIgnoreCase("true");
    }

    public String getMaxAmount() {
        return maxAmount;
    }

    public int getMaxAmountNum() {
        try {
            return Integer.parseInt(maxAmount);
        }catch (NumberFormatException e){
            e.printStackTrace();
            return 0;
        }
    }

    public String getMinAmount() {
        return minAmount;
    }

    public int getMinAmountNum(){
        try {
            return Integer.parseInt(minAmount);
        }catch (NumberFormatException e){
            e.printStackTrace();
            return 0;
        }
    }

    public int[] getDaysArray() {
        return daysArray;
    }

    public String getGranularity() {
        return granularity;
    }

    public int getGranularityNum(){
        int result = 0;
        try {
            result = Integer.parseInt(granularity);
            if (result<=0) result = 1;
            return result;
        }catch (NumberFormatException e){
            e.printStackTrace();
            return 1;
        }
    }

    public ArrayList<LnoaAp_dababyl_dababyyItem> getDetailItemList() {
        return detailItemList;
    }
}
